<?php

class Widgets extends Functions
{

	public $Menu;
	public $Window;
	public $Container;
	public $Error;
	public $Language;

	function __construct()
	{
		parent::__construct();
		$this->Window = new Window;
		$this->Menu = new MenuBar;
		$this->Container = new Containers;
		$this->Error = new Errors;
		set_error_handler(array($this->Error,'handler_error'));

		$this->run();
	}

	function run()
	{
    	$this->Window->set_title('powFTP - alpha 0.1');
        $this->Window->set_size_request(600, 500);
		$this->Window->connect_simple('destroy', array('Gtk', 'main_quit'));

		$this->Container->create('root', array('type'=>'vbox'));
		$this->Window->add($this->Container->get('root'));

		$this->createMenuBar();
		$this->Container->get('root')->pack_start($this->Menu->getMenuBar(), false, false);
		$this->Container->create('connect', array('type'=>'fixed'));

		//Barra conectar
		$this->Container->get('connect')->put( $this->input('Ip:','ip',array('entry_width'=>100,'entry_height'=>22,'value'=>'127.0.0.1')), 0, 0 );
		$this->Container->get('connect')->put( $this->input('Porta:','port',array('entry_width'=>30,'entry_height'=>22,'value'=>'21')), 135, 0 );
		$this->Container->get('connect')->put( $this->input('Usuario:','user',array('entry_width'=>70,'entry_height'=>22,'value'=>'root')), 215, 0 );
		$this->Container->get('connect')->put( $this->input('Senha:','pass',array('password'=>true,'entry_width'=>70,'entry_height'=>22,'value'=>'root')), 345, 0 );
		$this->Container->get('connect')->put( $this->button('Conectar','conectar'), 480, 0 );
		$this->getButton('conectar')->connect_simple('clicked',array($this, 'quickConnect'));
		
		$this->Container->get('root')->pack_start($this->test());		
		
		$this->Container->get('root')->pack_start($this->Container->get('connect'),false,false);
		$this->Container->get('root')->pack_start($this->separator(), false, false);

		$this->Window->show_all();
	}
	
	private function test()
	{
		$this->Ftp->setHost("127.0.0.1");
		$this->Ftp->setUser("root");
		$this->Ftp->setPass("root");
		$this->Ftp->connect();
		$this->Ftp->login();
		$content = $this->Ftp->ls("./");
				
		$scrolled_win = new GtkScrolledWindow();
		$scrolled_win->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
					
		$model = new GtkListStore(GdkPixbuf::gtype, 64);
		foreach($content['dirs'] as $item) {
		    $img = "media/images/blank.png";
			$pixbuf = GdkPixbuf::new_from_file($img); 
			$model->append(array($pixbuf, $item['name'])); 
		}
		
		$view = new GtkIconView($model); // note 4
		$view->set_pixbuf_column(0); // col 0 of the model
		$view->set_text_column(1); // col 1 of the model
		$view->set_selection_mode(Gtk::SELECTION_MULTIPLE); // note 5
		$view->set_columns(0); // note 6
		$view->set_item_width(120); // note 7
		
		$view->set_reorderable(true);
		
		$scrolled_win->add($view);
		
		
		return $scrolled_win;
				
	}
	
	private function createMenuBar()
	{
		$itens  = array (
			'file' => array (
				'label' 	=> 'Arquivo',
				'itens' 	=> array (
					//'connect' 		=> array (
					//	'label' => 'Conectar',
					//	'itens' => array (
					//		'teste1' => array ('label'=>'teste1')
					//	)
					//),
					//'quick_connect' => array ('label' => 'Desconectar'),
					//'separator' 	=> array ('label' => '---'),
					'quit' 			=> array ('label' => 'Sair')
				)
			),
			'about' => array (
				'label' 	=> 'Ajuda'
			)
		);

		$this->Menu->createMenuBar($itens);
		$this->Menu->getItem('quit')->connect_simple('activate', array('Gtk', 'main_quit'));
	}

		/*
		$window = new GtkWindow;
        $window->set_title(PROGRAM_NAME . " " . PROGRAM_VERSION);
        $window->set_position(GTK::WIN_POS_CENTER);
        $window->set_border_width(0);
        //$window->fullscreen();
        //$window->set_default_size("600", "400");
		$fixed = new GtkFixed();
		//$fixed->set_resize_mode(Gtk::RESIZE_IMMEDIATE);


		//Adicionando o MenuBar
		$fixed->put($m_bar,0,0);

		$combobox = GtkComboBoxEntry::new_text();
		$combobox->set_size_request(250,25);
		$combobox->append_text("hahahah");
		$combobox->prepend_text("hahahahaaaaaa");

		$fixed->put($combobox,0,25);

		$vpane = new GtkHPaned();
		$vpane->set_border_width(0);

		//$vpane->set_size_request(500,500);

		$frame_left = new GtkFrame();
		$hbox = new GtkHBox(false,0);


		$tb = new GtkToolbar();
		//Let the toolbar take the space it needs
		$tb->set_show_arrow(true);
		$tb->set_orientation(1);
		$tb->set_tooltips(true);
		$tb->set_style(0);

		//"New" toolbar button with stock icon
		$new  = new GtkToolButton( GtkImage::new_from_file("images/upload.png"),"Upload" );
		$tb->insert($new, -1);

		$open = new GtkToolButton( GtkImage::new_from_file("images/download.png"),"Download" );
		$open->connect_simple('clicked', 'onClickedToolButton', 'open');
		$tb->insert($open, -1);

		$hbox->pack_end($tb, false);
		$frame_left->add($hbox);
		$frame_left->set_shadow_type(Gtk::SHADOW_IN);

		$vpane->add1($frame_left);

		$frame_right = new GtkFrame();
		$frame_right->add($this->getLocalViewIcon2("C:\\tobias"));
		$frame_right->set_shadow_type(Gtk::SHADOW_IN);
		$vpane->add2($frame_right);
		//primeiro painel
		$hbox->pack_start($this->getLocalViewIcon("C:\\tobias"));

		$fixed->put($vpane,0,55);

		$window->add($fixed);
		$window->show_all();
		*/

}

?>
